package com.bestcem.xm.ticket.controller.v2;

import cn.hutool.core.lang.ObjectId;
import com.bestcem.xm.common.core.domain.web.ServiceResult;
import com.bestcem.xm.common.core.domain.web.XmResultJson;
import com.bestcem.xm.common.core.enums.ReqErrorCodeEnum;
import com.bestcem.xm.component.security.context.SecurityContextHolder;
import com.bestcem.xm.ticket.service.AlertRecordService;
import com.bestcem.xm.ticket.service.TicketRecordService;
import com.bestcem.xm.ticket.service.dto.RecordDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 工单 P2 接口
 *
 * @author XiaoYunSong <ys.xiao@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/17 17:47
 */
@Api(tags = "tickets")
@RestController(value = "TicketV2TicketRecordController")
@RequestMapping(value = "/ticket/v2", produces = MediaType.APPLICATION_JSON_VALUE)
public class TicketRecordController {

    @Resource
    private TicketRecordService ticketRecordService;
    @Resource
    private AlertRecordService alertRecordService;

    @Resource
    private HttpServletRequest request;

    @ApiOperation(value = "获取工单附加信息")
    @GetMapping(value = "/records/{id}")
    public XmResultJson<RecordDTO> getRecords(@PathVariable(value = "id") String id) {
        
        
        String orgId = SecurityContextHolder.getOrgId();
        String userId = SecurityContextHolder.getUserId();
        if (!ObjectId.isValid(id)) {
            return XmResultJson.fail(ReqErrorCodeEnum.PARAM_FORMAT, "id格式错误");
        }
        ServiceResult<RecordDTO> result = alertRecordService.getRecordInfo(id, userId, orgId);
        if (!result.isSuccess()) {
            return XmResultJson.fail(result.getErrorData(), result.getMsg());
        }
        RecordDTO data = result.getData();
        return XmResultJson.success(data);
    }
}
